<?php

declare(strict_types=1);

namespace App\Music\Model;

use Hyperf\Database\Model\SoftDeletes;
use Mine\MineModel;

/**
 * @property int $id 
 * @property string $uuid uuid
 * @property string $title 歌曲标题
 * @property int $album_id 专辑 ID
 * @property string $cover_art 封面图片
 * @property string $lyrics_file 歌词文件
 * @property string $mv_url mv地址
 * @property int $status 状态:1=正常,2=隐藏
 * @property int $weigh 权重
 * @property int $view_num 浏览次数
 * @property int $down_num 下载次数
 * @property int $base_view_num 基础浏览次数
 * @property int $base_down_num 基础下载次数
 * @property \Carbon\Carbon $created_at 创建时间
 * @property \Carbon\Carbon $updated_at 更新时间
 * @property string $deleted_at 
 */
class MusicSong extends MineModel
{
    use SoftDeletes;
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'music_song';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'uuid', 'title', 'album_id', 'cover_art', 'lyrics_file', 'mv_url', 'status', 'weigh', 'view_num', 'down_num', 'base_view_num', 'base_down_num', 'created_at', 'updated_at', 'deleted_at'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'album_id' => 'integer', 'status' => 'integer', 'weigh' => 'integer', 'view_num' => 'integer', 'down_num' => 'integer', 'base_view_num' => 'integer', 'base_down_num' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];

    /**
     * 歌曲列表
     * */
    public function artist()
    {
        return $this->belongsToMany(MusicArtist::class, 'music_song_artist_relations', 'song_id', 'artist_id');
    }

    /**
     * 专辑
     * */
    public function album()
    {
        return $this->belongsTo(MusicAlbum::class, 'album_id', 'id');
    }

    /**
     * 标签
     * */
    public function tag()
    {
        return $this->belongsToMany(MusicSongTag::class, 'music_song_tag_relations', 'song_id', 'tag_id');
    }

    /**
     * 类型
     * */
    public function type()
    {
        return $this->belongsToMany(MusicSongType::class, 'music_song_type_relations', 'song_id', 'type_id');
    }

    /**
     * 文件
     * */
    public function songFiles()
    {
        return $this->hasMany(MusicSongFile::class,'song_id');
    }


}
